/**
 * 部门添加js
 */
var comValidform=null;
var returnStatus=false;
var userChannelAdd={
	dataCache:null,

	showRole:function(){
		//获取所有角色
		var url ='mgr/SysRoleCtrl/getSysRoleList';
		var params={
			'curPage':0,
			'pageSize':9999,
			'roleType':2
		};
		var cb = function(data){
			userChannelAdd.dataCache=data.result;
			var rolesCache=userChannelAdd.dataCache;
			var tr='';
			for(var i=0;i<rolesCache.length;i++){
				if(i%4==0){
					tr+='<tr style="height: 25px;">';
				}
				var id=rolesCache[i].sysRole.id;
				var name=rolesCache[i].sysRole.name;
				tr+='<td><input type="radio" name="roleId" value="'+id+'" />'+name+'</td>';
				if(i%4==3){
					tr+='</tr>';
				}
			}
			$('#roleTable').append(tr);
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},
		
	startEvent:function(){
		comValidform=$(".com-addForm").Validform({
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				var url = 'mgr/userChannelCtrl/save';
				//var params;
				//var params = jsUtils.serializeJson($('.com-addForm'));
				var name = $('input[name="name"]').val().trim();
				var channelDesc = $('textarea[name="channelDesc"]').val().trim();
				var userRoleId = $("input[name='roleId']:checked").val();
				var channelId = $("input[name='channelId']").val();

				if(userRoleId == null || userRoleId == '' ){
					alert("请选择管理角色再提交！");
					return false;
				}
				var params ={
					'name':name,
					'channelDesc':channelDesc,
					'userRoleId':userRoleId,
					'channelId':channelId
				};

				var cb = function(data){
					alert(data.msg);
					//成功返回
					if(data.resultCode==200){
						//关闭窗口并刷新数据
						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return returnStatus;
			}
		});
	},
	
	init:function(){
		userChannelAdd.startEvent();
		userChannelAdd.showRole();
		
	}
}
$(document).ready(function() {
	userChannelAdd.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}